<template>
  <el-dialog
    :title="content.tips"
    :visible.sync="dialogVisible"
    width="30%"
    :before-close="myClose"
  >
    <p>您正在{{ content.tips }}活动，请输入密码</p>
    <!-- <el-input v-model="password" placeholder="" type="password" /> -->
    <el-input v-model="password" placeholder="请输入密码" show-password />
    <p>活动标题：{{ content.title }}</p>
    <p>当前活动状态:{{ content.status | filteActivity }}</p>

    <span slot="footer" class="dialog-footer">
      <el-button @click="$emit('fnclose', false)">取 消</el-button>
      <el-button type="primary" @click="handleUpdate">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  props: {
    // title: {
    //   require: true,
    //   type: String,
    //   default: '提示'
    // },
    dialogVisible: {
      require: true,
      type: Boolean,
      default: false
    },
    content: {
      type: Object,
      default: null
    }
  },
  data() {
    // 0未开始,1进行中,2已暂停,3已结束,-1已取消
    return {
      password: ''
    }
  },
  methods: {
    myClose() {
      this.$emit('fnclose', false)
    },
    handleUpdate() {
      let status = ''
      if (this.content.tips === '取消') {
        status = '-1'
      } else if (this.content.tips === '暂停') {
        status = '2'
      } else if (this.content.tips === '重启') {
        status = '1'
      }
      if (this.password === '') {
        this.$message.error('密码不能为空')
        return
      }
      const id = String(this.content.id)
      this.$put('/web/activity/updateStatus', {
        'entity': {
          status,
          id,
          password: this.password
        }
      }, 'json').then((res) => {
        if (res.data.code === '0') {
          this.$message.success(this.content.tips + '成功')
          this.$emit('fnclose', { isSearch: true })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
p {
  height: 30px;
  line-height: 30px;
}
</style>
